package com.bbs2.util;

public class Page {
	private int totalSize;
	private int currentPage = 1;
	private int pageSize = 5;
	
	public Page(){}
	public Page(int totalSize,int pageSize){
		this.totalSize = totalSize;
		this.pageSize = pageSize;
	}
	public int getStartNum() {
			return getPageSize()*(getCurrentPage()-1);
	}
	public int getTotalSize() {
		return totalSize;
	}
	public void setTotalSize(int totalSize) {
		this.totalSize = totalSize;
	}
	public int getTotalPages() {
		int result = getTotalSize()/getPageSize();
		if(getTotalSize()%getPageSize() == 0){
			return result;
		}else{
			return result+1;
		}
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		if(currentPage <= 0){
			this.currentPage = 1;
		}else if(currentPage >= getTotalPages()){
			this.currentPage = getTotalPages();
		}else{
			this.currentPage = currentPage;
		}
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public boolean isFirst(){
		return getCurrentPage() == 1;
	}
	public boolean isLast(){
		return getCurrentPage() == getTotalPages();
	}
	public boolean isNext(){
		return getCurrentPage() < getTotalPages();
	}
	public boolean isPrev(){
		return getCurrentPage() > 1;
	}
}
